export function getRouter(data, newRoutes) {
    return new Promise((resolve) => {
        data.forEach((l) => {
            // 1 菜单  2 页面  3 按钮
            if (l.status === 1 && l.menuType == 1) {
                let item = {
                    path: l.componentPath,
                    name: l.componentName,
                    component: (resolve) => require(["@/views/" + (l.url ? l.url : 'index')], resolve),
                    meta: {
                        title: l.name,
                        icon: l.icon,
                    },
                    children: [],
                };
                newRoutes.push(item);
                getRouter(l.children, item.children);
            } else if (l.status === 1 && l.menuType == 2) {
                if (l.menuParentId == "0") {
                    newRoutes.push({
                        path: "/",
                        name: "",
                        component: () => import("@/views/index"),
                        redirect: l.componentPath,
                        children: [
                            {
                                path: l.componentPath,
                                name: l.componentName,
                                component: (resolve) =>
                                    require(["@/views/" + l.url], resolve),
                                meta: {
                                    title: l.name,
                                    icon: l.icon,
                                },
                            },
                        ],
                    });
                } else {
                    // console.log("@/views/" + l.url)
                    newRoutes.push({
                        path: l.componentPath,
                        name: l.componentName,
                        component: (resolve) => require(["@/views/" + l.url], resolve),
                        meta: {
                            title: l.name,
                            icon: l.icon,
                        },
                    });
                }
            }
        });
        console.log(newRoutes)
        resolve(newRoutes);
    });
}
